<template>
<div class="vue-box sbot sbot-fluid">
  <!-- 参数栏 -->
  <div class="c-panel">
    <el-form :inline="true">
      <!-- 表单 -->
      <sa-item v-model="m.name" type="text" name="模板名称" br />
      <sa-item v-model="m.templateCode" type="text" name="模板编码" br />
      <sa-item v-model="m.templateText" type="text" name="模板内容" br />
      <sa-item v-model="m.sid" type="enum" jtype="3" :jv="dims.SD" name="所属服务" br />
      <sa-item v-model="m.sourceType" type="enum" jtype="3" :jv="dims.SMS_SOURCE" name="短信来源" br />
      <sa-item v-model="m.type" type="enum" jtype="3" :jv="dims.SMS_TYPE" name="短信类型" br />
      <sa-item v-model="m.appKey" type="text" name="APPKEY" br />
      <sa-item v-model="m.appSecret" type="text" name="APPSECRET" br />
      <sa-item v-model="m.api" type="text" name="SMSAPI" br />
      <sa-item v-model="m.sign" type="text" name="签名" br />
      <sa-item v-model="m.region" type="text" name="服务区域列" br />
      <sa-item v-model="m.status" type="enum" jtype="3" :jv="dims.YES_OR_NO" name="启用状态" br />
      <sa-item v-model="m.note" type="text" name="描述" br />
      <sa-item v-model="m.sort" type="num" name="序号" br />
    </el-form>
  </div>
</div>
</template>

<script>
export default {
  name: 'sms-temp-update',
  props: {
    param: Object
  },
  data() {
    return {
      // 超级对象
      m: this.createModel(),
      dims: this.param.dims
    }
  },
  created: function () {},
  methods: {
    createModel() {
      return {
        id: this.param.id,
        name: this.param.name,
        templateCode: this.param.templateCode,
        templateText: this.param.templateText,
        sign: this.param.sign,
        region: this.param.region,
        sid: this.param.sid,
        type: this.param.type,
        sourceType: this.param.sourceType,
        appKey: this.param.appKey,
        appSecret: this.param.appSecret,
        api: this.param.api,
        status: this.param.status,
        note: this.param.note,
        sort: this.param.sort
      }
    },
    // 变更
    ok: function () {
      // 表单校验
      let m = this.m;
      sa.checkNull(m.name, '请输入模板名');
      sa.checkNull(m.smsCode, '请输入模板编码');
      sa.checkNull(m.type, '请选择短信来源');
      sa.checkNull(m.sourceType, '请选择短信类型');
      sa.checkNull(m.appKey, '请输入AccessKey ID');
      sa.checkNull(m.appSecret, '请输入AccessKey Secret');
      sa.checkNull(m.smsApi, '请输入接口地址');
      sa.checkNull(m.sign, '请输入签名');
      sa.checkNull(m.smsTemplate, '请输入模板内容');
      sa.checkNull(m.sid, '请选择服务');
      // 添加
      sa.ajax('/sms/template/update', m, function (res) {
        if (res.code == 200) {
          sa.alert(res.msg, function () {
            this.m = this.createModel();
            sa.closeModel();
            sa.currView().f5();
          }.bind(this));
        }
      }.bind(this), {
        type: 'post'
      });
    }
  }
}
</script>

<style scoped></style>
